package com.sense.feel.login.model

import com.sense.feel.login.model.net.LoginApi
import com.sense.kukoo.common.mvvm.model.BaseMvvmModel
import com.sense.kukoo.common.repo.http.KukooHttpManager
import okhttp3.RequestBody
import com.sense.kukoo.common.repo.bean.ResultBean
import com.sense.kukoo.common.repo.bean.UserInfo

class PhoneLoginModel : BaseMvvmModel() {
    /*phoneNumber	string
    要接收信息的手机号，包含国家代码，如8618300000000

    rand	string
    验证票据需要的随机字符串

    source	string
    发送短信验证的场景来源, Login代表登录, Settle代表B端入驻

    Enum:
    Array [ 2 ]
    ticket	string
    验证码返回给用户的票据*/
    suspend fun getVerifyCode(
        phoneNumber: String,
        rand: String,
        ticket: String
    ): ResultBean<String>? {
        val hashMap = HashMap<String, Any>()
        hashMap.put("phoneNumber", phoneNumber)
        hashMap.put("rand", rand)
        hashMap.put("ticket", ticket)
        hashMap.put("source", "Login")
        val mRequestBody: RequestBody = KukooHttpManager.createRequestBody(hashMap)

        return KukooHttpManager.instance.createHttpClient(LoginApi::class.java)
            .getVerifyCode(mRequestBody)
    }

    /*hasInvitedFive	boolean
    是否限制注册，只要不为true，就是不限制

    inviterUnique	string
    邀请人特殊码

    keyUuid	string
    发送验证码接口返回的keyUuid

    phoneNumber	string
    手机号

    signUpUniqueCode	string
    签约陪玩师特殊码

    verifyCode	string
    验证码*/
    suspend fun login(
        hasInvitedFive:Boolean,verifyCode:String, phoneNumber: String,signUpUniqueCode: String,
        inviterUnique: String, keyUuid: String
    ): ResultBean<UserInfo>? {
        val hashMap = HashMap<String, Any>()
        hashMap.put("hasInvitedFive",hasInvitedFive)
        hashMap.put("inviterUnique",inviterUnique)
        hashMap.put("keyUuid",keyUuid)
        hashMap.put("signUpUniqueCode",signUpUniqueCode)
        hashMap.put("verifyCode",verifyCode)
        hashMap.put("phoneNumber", phoneNumber)
        val mRequestBody: RequestBody = KukooHttpManager.createRequestBody(hashMap)

        return KukooHttpManager.instance.createHttpClient(LoginApi::class.java)
            .login(mRequestBody)
    }


    override fun onModelCleared() {}
}